<template>
  <component
    :is="multiple ? 'el-checkbox-group' : 'el-radio-group'"
    v-model="myValue"
    v-bind="$attrs"
    v-on="$listeners">
    <template v-if="multiple">
      <el-checkbox
        v-for="item in options"
        :key="item.code"
        :label="item.code"
        :disabled="disabledItem ? disabledItem(item) : false">{{item.dictName}}</el-checkbox>
    </template>
    <template v-else>
      <el-radio
        v-for="item in options"
        :key="item.code"
        :label="item.code"
        :disabled="disabledItem ? disabledItem(item) : false">{{item.dictName}}</el-radio>
    </template>
  </component>
</template>

<script>
export default {
  name: "YCodeCheckBox",
  model:{
    prop: 'value',
    event: 'change'
  },
  inject: ['getDict'],
  props:{
    value: {},
    dict: String,
    multiple: {
      type: Boolean,
      default: false
    },
    disabledItem: Function
  },
  computed:{
    myValue:{
      get(){
        return this.value;
      },
      set(val){
        this.$emit('change', val);
      }
    }
  },
  asyncComputed:{
    options(){
      return this.getDict(this.dict);
    },
  }
}
</script>

<style scoped>

</style>